package com.cpi.cornpp.productpurchase.services;

import java.util.ArrayList;
import java.util.List;

import com.cpi.cornpp.common.exception.CornPPException;
import com.cpi.cornpp.productpurchase.converter.ProductPurchaseConverter;
import com.cpi.cornpp.productpurchase.dao.ProductPurchaseDAO;
import com.cpi.cornpp.productpurchase.dto.ProductPurchaseDTO;
import com.cpi.cornpp.productpurchase.exception.ProductPurchaseException;
import com.cpi.cornpp.productpurchase.view.ProductPurchaseView;

public class ProductPurchaseService {

	

	public List getProductPurchaseList(ProductPurchaseView view) throws ProductPurchaseException {
		ProductPurchaseDAO dao = null;
		ProductPurchaseConverter converter = null;
		ProductPurchaseDTO dto = null;		
		List dtos = null;
		List views = null;
		
		try {
			dao = new ProductPurchaseDAO();
			dto = new ProductPurchaseDTO();
			converter = new ProductPurchaseConverter();
			dtos = new ArrayList(0);
			views = new ArrayList(0);
			
			
			// La vista la convierto en un DTO
			dto = converter.convert(view);
			// Obtengo el listado de los clientes
			dtos = dao.list(dto);
			// Mando convertir el listado en la vista de retorno
			views = converter.convertDtos(dtos);
		} catch (ProductPurchaseException ProductPurchaseException) {			
			ProductPurchaseException.printStackTrace(System.out);
			ProductPurchaseException= new ProductPurchaseException(ProductPurchaseException , CornPPException.LAYER_SERVICE,CornPPException.ACTION_LISTS);
			throw ProductPurchaseException;

		}
		catch (Exception e){
			ProductPurchaseException ProductPurchaseException=null;
			e.printStackTrace(System.out);
			ProductPurchaseException= new ProductPurchaseException(e , CornPPException.LAYER_SERVICE,CornPPException.ACTION_LISTS);
			throw ProductPurchaseException;
		}
		return views;
	}
}
